#include "rocket_1.h"

extern int G_H,G_W;

Rocket_1::Rocket_1(QPoint begin, SCENE *scene, QTimeLine *global_tl, CASH *cash):QGraphicsObject()
{

    shot = new SOUND_POWER(cash,"Res/Sound/Enemy/Enemy_1/shot.ogg",this);
    shot->Play_Now();

    this->cash = cash;

    point=15;

    border = new QPainterPath();
    im = cash->cash_pixmap->value("Res/weapons/rocket_1/rocket_1.png");

    this->setZValue(0.5);

    this->setPos(begin);

    anim_rocket = new QGraphicsItemAnimation();

    rocket_time_line = new QTimeLine(600);
    rocket_time_line->setEasingCurve(QEasingCurve::Type(7));
    rocket_time_line->setFrameRange(0,1);

    anim_rocket->setTimeLine(rocket_time_line);
    anim_rocket->setItem(this);
    anim_rocket->setPosAt(0,begin);
    anim_rocket->setPosAt(1,QPoint( begin.x(),G_H+100 ) );

    rocket_time_line->start();

    collisia_control = new COLLISIA_CONTROL(scene,((QGraphicsObject*)this),this,global_tl,cash,50);

    connect(collisia_control,SIGNAL(Collisia(QPointF,int)),this,SLOT(Damage_Detected(QPointF,int)));
    connect(rocket_time_line,SIGNAL(finished()),SLOT(deleteLater()));

    QTimer::singleShot(100, this, SLOT(set_shape()));
}

QPainterPath Rocket_1::shape() const
{

    return *border;

}

QRectF Rocket_1::boundingRect() const
{

    return QRectF( QPointF(0,0),im->size() );

}

void Rocket_1::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->save();
    painter->drawPixmap( 0,0,*im);
    painter->restore();

}

Rocket_1::~Rocket_1()
{
}

int Rocket_1::type() const
{

    return point;

}

void Rocket_1::set_shape()
{
    border = this->cash->cash_poly->value("Res/weapons/rocket_1/rocket_1.poly");
}

void Rocket_1::Damage_Detected(QPointF a, int d)
{

    a = QPointF();
    point-=d;

    if(point<=0) this->scene()->removeItem(this);

}
